<template>
  <!-- 列表 -->
  <ContentWrap>
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="权利人序号" align="center" prop="id">
        <template #default="scope">
          <el-link type="primary" @click="openObligeeForm('update', scope.row.id)">{{
            scope.row.id
          }}</el-link>
        </template>
      </el-table-column>
      <el-table-column label="权利人名称" align="center" prop="obligeeName" />
      <el-table-column label="权利人类型" align="center" prop="obligeeType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.OBLIGEE_TYPE" :value="scope.row.obligeeType" />
        </template>
      </el-table-column>
      <el-table-column label="权利人证件类型" align="center" prop="obligeeCertificateType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ID_TYPE" :value="scope.row.obligeeCertificateType" />
        </template>
      </el-table-column>
      <el-table-column label="权利人证件号" align="center" prop="obligeeCertificate" />
      <el-table-column label="权利人电话" align="center" prop="obligeePhone" />
      <el-table-column label="权利人地址" align="center" prop="obligeeAddress" />
      <el-table-column label="法人名称" align="center" prop="corporationName" />
      <el-table-column label="法人证件类型" align="center" prop="corporationCertificateType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.ID_TYPE" :value="scope.row.corporationCertificateType" />
        </template>
      </el-table-column>
      <el-table-column label="法人证件号" align="center" prop="corporationCertificate" />
      <el-table-column label="经办人" align="center" prop="obligeeLiasion" />
      <el-table-column label="经办人电话" align="center" prop="liasionPhone" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="状态" align="center" prop="status">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.SYS_STATUS" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        :formatter="dateFormatter"
        width="180px"
      />
    </el-table>
  </ContentWrap>
  <ObligeeForm ref="obligeeFormRef"  @success="getList" />
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { LandApi } from '@/api/zszx/land'

import ObligeeForm from '@/views/zszx/obligee/ObligeeForm.vue'
const obligeeFormRef = ref()
const openObligeeForm = (type: string, id?: number) => {
  // console.log(type, id,props.landId)
  obligeeFormRef.value.open(type, id)
}

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗

const props = defineProps<{
  landId?: number // 宗地序号（主表的关联字段）
}>()
const loading = ref(false) // 列表的加载中
const list = ref([]) // 列表的数据

/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    list.value = await LandApi.getObligeeListByLandId(props.landId)
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNo = 1
  getList()
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
